/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.skjeffrey.creational.staticfactorymethod;

import com.skjeffrey.utils.file.SKFile;

/**
 *
 * @author x
 */
public class Standard extends StaticFactoryMethod {

    @Override
    public void generate() {
        this.results+="public abstract class "+this.product+" {\n\tpublic abstract create();\n}\n";
        
        int index=-1;
        index=this.concreteProducts.indexOf(",", 0);

        while(-1!=index){
            int nextIndex=this.concreteProducts.indexOf(",", index+1);
            if(-1==nextIndex){
                break;
            }
            
            this.results+="public class "+this.concreteProducts.substring(index+1, nextIndex)+" {\n\t@Override\n\tpublic create(){\n\t}\n}\n";
            index=nextIndex;
        }
    }

    public void setCreator(String creator){
        this.creator=creator;
    }

    public void setProduct(String product){
        this.product=product;
    }

    public void addConcreteProduct(String concreteProduct){
        this.concreteProducts+=","+concreteProduct;
    }

    public boolean toFile(String filePath){
        SKFile file=null;
        file.setFilePathName(filePath+this.creator);
        file.write( this.results);
        return true;
    }

    @Override
    public String toString(){
        return this.results;
    }

    private String creator="";
    private String product="";
    private String concreteProducts="";

    private String results="";
}
